import { services } from '@/config'
import { getCodeObj } from '@/api/space/fyroomhouse'

const validateCode = (rule, value, callback) => {
  getCodeObj(value).then(response => {
    if (window.boxType === 'edit') {
      return callback()
    }
    const result = response.data.data
    if (result && result.length !== 0) {
      callback(new Error('房屋编码已存在'))
    } else {
      callback()
    }
  })
}

export const tableOption = {
  labelPosition: 'left',
  labelSuffix: '：',
  labelWidth: 120,
  gutter: 0,
  menuBtn: true,
  submitBtn: true,
  submitText: '提交',
  emptyBtn: true,
  emptyText: '清空',
  menuPosition: 'center',
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  align: 'center',
  searchMenuSpan: 6,
  viewBtn: true,
  column: [
    {
      type: 'input',
      label: '房间ID',
      prop: 'id',
      span: 12,
      display: false,
      hide: true
    },
    {
      prop: 'unid',
      span: 12,
      type: 'input',
      label: '唯一编码',
      rules: [],
      display: false,
      required: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人ID',
      prop: 'createId',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人姓名',
      prop: 'createName',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建时间',
      prop: 'createTime',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人所属OU的ID',
      prop: 'deptId',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '创建人所属OU的全称',
      prop: 'deptFullname',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '最后修改人信息',
      prop: 'updateBy',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '最后修改时间',
      prop: 'updateTime',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '租户ID',
      prop: 'tenantId',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'input',
      label: '数据删除标记',
      prop: 'delFlag',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'tree',
      label: '所属楼栋',
      prop: 'edificeId',
      span: 24,
      hide: true,
      rules: [
        {
          message: '所属楼栋必须填写',
          required: true
        }
      ]
    },
    {
      type: 'input',
      label: '所属楼栋全称',
      prop: 'parentFullname',
      span: 12,
      width: 200,
      display: false,
      hide: false
    },
    {
      label: '楼层名称',
      prop: 'storeyId',
      span: 24,
      rules: [
        {
          message: '楼层名称必须填写',
          required: true
        }
      ],
      hide: true
    },
    {
      type: 'input',
      label: '楼层名称',
      prop: 'storeyName',
      span: 12,
      display: false,
      hide: false
    },
    {
      type: 'input',
      label: '房间名称',
      prop: 'name',
      search: true,
      searchLabelWidth: 85,
      span: 12,
      rules: [
        {
          message: '房间名称必须填写',
          required: true
        }
      ]
    },
    {
      type: 'input',
      label: '房屋编码',
      width: 120,
      prop: 'code',
      span: 12,
      required: false,
      addDisplay: false,
      rules: [
        {
          required: true,
          message: '请输入房屋编码',
          trigger: 'blur'
        },
        { validator: validateCode, trigger: 'blur' }
      ]
    },
    {
      label: '排序号',
      prop: 'ordernumber',
      addDisplay: false,
      type: 'number',
      rules: [
        {
          message: '排序号必须填写',
          required: false
        }
      ],
      span: 12
    },
    {
      type: 'input',
      label: '产权年限',
      prop: 'ageLimit',
      searchLabelWidth: 85,
      search: true,
      span: 12,
      append: '年'
    },
    {
      type: 'radio',
      label: '配套电梯',
      search: true,
      searchLabelWidth: 85,
      prop: 'elevator',
      span: 12,
      value: '1',
      dicData: [
        {
          label: '无',
          value: '0'
        },
        {
          label: '有',
          value: '1'
        }
      ],
      display: true,
      props: {
        label: 'label',
        value: 'value'
      }
    },
    {
      type: 'select',
      label: '房屋朝向',
      prop: 'orientation',
      props: { label: 'label', value: 'value' },
      dicUrl: `${services.spaceService}fyroomhouse/getOptionList/house_face`,
      dicMethod: 'get',
      searchLabelWidth: 85,
      span: 12,
      search: true
    },
    {
      type: 'input',
      label: '房屋类型',
      prop: 'typeName',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'select',
      label: '房屋类型', // {BG：办公用房、YW：业务用房、JZ：居住用房、QT：其他用房}
      prop: 'typeCode',
      span: 12,
      search: true,
      searchLabelWidth: 85,
      props: { label: 'label', value: 'value' },
      dicUrl: `${services.spaceService}fyroomhouse/getOptionList/house_type`,
      dicMethod: 'get',
      hide: false
    },
    {
      type: 'select',
      label: '状态', // ：0：代表空闲，1：预定中， 2：使用中，3:维修中，4：待处置，5：已处置
      prop: 'status',
      span: 12,
      search: true,
      dataType: 'number',
      searchLabelWidth: 85,
      props: { label: 'label', value: 'value' },
      dicUrl: `${services.spaceService}fyroomhouse/getOptionList/house_status`,
      dicMethod: 'get'
    },
    {
      type: 'textarea',
      label: '房屋用途',
      prop: 'purpose',
      search: true,
      searchLabelWidth: 85,
      span: 24
    },
    {
      type: 'number',
      label: '使用面积',
      prop: 'useArea',
      span: 12,
      append: '平米'
    },
    {
      type: 'number',
      label: '使用面积大于',
      prop: 'useAreaGt',
      searchLabelWidth: 110,
      display: false,
      search: true,
      searchRange: true,
      span: 12,
      append: '平米'
    },
    {
      type: 'number',
      label: '使用面积小于',
      prop: 'useAreaLt',
      display: false,
      searchLabelWidth: 110,
      search: true,
      span: 12,
      append: '平米'
    },
    {
      type: 'input',
      label: '建筑面积',
      prop: 'floorage',
      span: 12,
      append: '平米'
    },
    {
      type: 'radio',
      label: '是否危房',
      prop: 'dangerous',
      span: 12,
      value: '0',
      dicData: [
        {
          label: '否',
          value: '0'
        },
        {
          label: '有',
          value: '1'
        }
      ],
      display: true,
      props: {
        label: 'label',
        value: 'value'
      }
    },
    {
      type: 'radio',
      label: '是否在施工',
      prop: 'construction',
      width: 100,
      span: 12,
      value: '0',
      dicData: [
        {
          label: '否',
          value: '0'
        },
        {
          label: '有',
          value: '1'
        }
      ],
      display: true,
      props: {
        label: 'label',
        value: 'value'
      }
    },
    {
      type: 'input',
      label: '建造年代',
      prop: 'constructionAge',
      search: true,
      searchLabelWidth: 85,
      span: 12
    },
    {
      type: 'input',
      label: '租金', // 类型为宿舍才显示
      prop: 'rent',
      span: 12,
      append: '元'
    },
    {
      type: 'select',
      label: '房屋户型', // {单间、一房一厅、两房一厅、三房两厅}
      prop: 'layout',
      search: true,
      searchLabelWidth: 85,
      span: 12,
      props: { label: 'label', value: 'value' },
      dicUrl: `${services.spaceService}fyroomhouse/getOptionList/house_unit_type`,
      dicMethod: 'get'
    },
    {
      type: 'select',
      label: '装修程度', // {毛坯、普装、精装、豪华装}
      prop: 'renovation',
      search: true,
      searchLabelWidth: 85,
      span: 12,
      props: { label: 'label', value: 'value' },
      dicUrl: `${services.spaceService}fyroomhouse/getOptionList/house_program`,
      dicMethod: 'get'
    },
    {
      type: 'tree',
      label: '管理单位',
      prop: 'belongouinfoId',
      dicUrl: `${services.adminService}dept/tree`,
      props: { label: 'name', value: 'id' },
      dicMethod: 'get',
      span: 12,
      rules: [
        {
          required: false
        }
      ]
    },
    {
      type: 'input',
      label: '房屋价格',
      prop: 'price',
      span: 12,
      append: '元'
    },
    {
      type: 'input',
      label: '房间编号为后期条码用',
      prop: 'assetNumber',
      span: 12,
      display: false,
      hide: true
    },
    {
      type: 'textarea',
      label: '备注',
      prop: 'remarks',
      span: 24
    },
    {
      type: 'input',
      label: '数据权限编码，从区域开始一直按着全编码按照表之间的依赖一直延续下去',
      prop: 'dataCode',
      span: 12,
      display: false,
      hide: true
    },
    {
      label: '附件信息',
      prop: 'uploadPage',
      type: 'input',
      formslot: true,
      slot: true,
      span: 24,
      hide: true
    }
  ]
}
